package com.iflytek.autofly.setting.util;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;

public class MultiMap<K, V> {
    private final HashMap<K, List<V>> mStore = new HashMap<K, List<V>>();

    /**
     * retrieve a non-null list of values with key K
     *
     * @param key
     * @return List<V>
     */
    public List<V> getAll(K key) {
        List<V> values = mStore.get(key);
        return values != null ? values : Collections.<V>emptyList();
    }

    public void put(K key, V val) {
        List<V> curVals = mStore.get(key);
        if (curVals == null) {
            curVals = new ArrayList<V>(3);
            mStore.put(key, curVals);
        }
        curVals.add(val);
    }
}